local desc_wjsl_mode = [[
  # 巅峰神塔简介
  ___

  人数：2~8人，最多3人玩家组队（需要游戏人数大于4），当游戏人数2人时为单人爬塔模式。否则需要抵抗多敌人人机。

  胜利条件：玩家通关第42层(多人为49层)。

  失败条件：玩家全部死亡或者投降。玩家自由选将不在白名单列表。敌对人机总数小于等于玩家总数。

  层主技能（有“层数：X”的人机主公，X为层数）：1.随机技能：每次层主复活会获得额外随机技能。2.关卡技能：层主会在固定层数获得永久不变的技能

  神将层主：实力远高于层主，击败后获得其神将身上任意一个技能。

  卡牌：无视开启的扩展卡组。会自动过滤其他卡组，只留下标准包，军争包，浪包。去除诸葛连弩，延时锦囊牌

  武将扩展包：无视开启的扩展包，只从白名单中随机12个武将任意选1个。白名单具体在群内（835104528）简介文本下面。

  规则：冲塔层数，击败神将。到达神塔巅峰42层(多人为49层)。每层对抗白名单将池内随机的不重复武将。当每次击杀层主，塔层层数+1，复活后重置武将并摸等量的牌；层主根据层数获得随机技能、最大体力、初始手牌；强度呈线性增长

  玩家击败层主后会根据不同层数获得选项增益。增益包括【随机的永久技能】，【随机的最大体力值上限】，【随机的金币】，【魔盒】、【杀伤】、【杀数】、【锦伤】标记属性加成，【守护天使】（复活甲设定）等。

]]

--是否开启写入武将白名单
local ISwrite = false
--开启测试
local IStest = false
--玩家测试武将
local TESTgen = "mouxusheng"
--测试AI武将（避免自由选）
local TESTgens = {"blank_shibing","xielingyu","zhouyi","ol__tengfanglan","dongyun","l__zhangliao","ex__simayi","ol_ex__zhangjiao","ty_ex__zhuran","l__lvbu","ty__yanghu","zhaotongzhaoguang","joy__xunyou","miniex__huangyueying","ty__yanghu","joy__xunyou","godzhaoyun","js__guanyu","lvlingqi","dukui","ty_ex__wuyi","ol_ex__sunjian","xizhicai","qinmi","godganning","ty__chenlin","ex__ganning","yuejiu","caomao","ty__lidian","ol__luyusheng","godganning","ty_ex__caozhi","zhaotongzhaoguang"}
--精选热门武将不必自由选
local HOTgenerals = {"js__liubei","qinmi","ty__caochun","ol__yanghu","l__zhangliao","m_ex__xusheng","ol__huangzu","hulao2__godlvbu","mou__machao","os_ex__guohuai","liyixiejing"}
--过滤其他卡组（只允许白名单的卡组加入牌堆）
local WHILEcards = {"standard","standard_cards","maneuvering","lang_cards","tenyear_token","mobile_derived","ol_token","overseas_token"}
--保留玩家本模式重要的标记
local SAVEmarks = {"curlayerphase","@slash_dmg","@trick_dmg","@pdlbox","@gold_num","@df_lingxin","@shieldnum","@slash_num"}

--初始化游戏数据
local initGameData = {
  i_layer = 1,--初始关卡
  t_layer = 49,--总关卡
  initgold = 30,--初始金币
  goldpower = 1.7,--获得随机金币*倍率
  maxctiwin = 4,--连胜最多层数即中断当前玩家阶段
  lordslayer = 9,--层主队友+1需要每几层
  lordsperup = 7,--层主队友成长一次需要每几层
  defbossstep = 7,--每过几层对战boss
  laygetskill_n = 5,--层主每过几关获得技能，包括体力上限
  rewd_intval = {{13,1,4},{25,2,5},{35,3,6}}, --关卡选项变化（可以多选与加选）
  layownskills = {mashu = 2,l_wuqian = 14,os_ex__paoxiao = 21,langxi = 25,wjsl_tazhen = 32,liji = 35,df_fengkuang = 38}, --层主关卡技能
  rewards = {gaingold=0.1,skills = 0.12,maxhp = 0.1,lingxin = 0.1,magicbox=0.08,extraslash_num=0.1,angelbless=0.1,slash_dmg_sel=0.08,trick_dmg_sel=0.1,shieldnum = 0.12},--玩家奖励概率配置
  rulename = "#wjsl_rule", --游戏模式名
  godboss = {"godzhangjiao","godsunce","godzhaoyun","godganning","godtaishici","godmachao","godliubei"},--神将boss
  meetpuyuan = {rate = 0.08,meet={3,10}}, --rate是每次概率上升值，meet遇见商店最多次，每几层重置
  initshopskills = 8
}
--初始化游戏数据(单人)
local initGameDataByLess = {
  i_layer = 1,--初始关卡
  t_layer = 42,--总关卡
  initgold = 40,--初始金币
  goldpower = 1.5,--获得随机金币*倍率
  maxctiwin = 4,--连胜最多层数即中断当前玩家阶段
  lordslayer = 60,--层主队友+1需要每几层
  lordsperup = 60,--层主队友成长一次需要每几层
  defbossstep = 7,--每过几层对战boss
  laygetskill_n = 4,--层主每过几关获得技能，包括体力上限
  rewd_intval = {{13,1,4},{25,2,5},{35,3,6}}, --关卡选项变化（可以多选与加选）
  layownskills = {mashu = 2,l_wuqian = 14,os_ex__paoxiao = 21,langxi = 25,wjsl_tazhen = 32,liji = 35,df_fengkuang = 38}, --层主关卡技能
  rewards = {gaingold=0.1,skills = 0.12,maxhp = 0.1,lingxin = 0.1,magicbox=0.08,extraslash_num=0.1,angelbless=0.1,slash_dmg_sel=0.08,trick_dmg_sel=0.1,shieldnum = 0.12},--玩家奖励概率配置
  rulename = "#wjsl_rule", --游戏模式名
  godboss = {"godzhangjiao","godsunce","godzhaoyun","godganning","godtaishici","godmachao","godliubei"},--神将boss
  meetpuyuan = {rate = 0.07,meet={2,10}}, --rate是每次概率上升值，meet遇见商店最多次，每几层重置
  initshopskills = 8
}

local EndLessPractice = require "packages/lang/EndLessPractice"

local wjsl_getLogic = function()
  local wjsl_logic = GameLogic:subclass("wjsl_logic")

  function wjsl_logic:initialize(room)
    GameLogic.initialize(self, room)
    self.role_table = {
      { "lord" },
      { "lord", "rebel" },
      { "lord", "rebel", "rebel" },
      { "lord", "rebel", "rebel", "rebel" },
      { "lord", "rebel", "rebel", "rebel", "rebel" },
      { "lord", "loyalist", "loyalist", "loyalist", "rebel", "rebel" },
      { "lord", "rebel", "rebel", "rebel", "rebel", "rebel", "rebel" },
      { "lord", "loyalist", "loyalist", "rebel", "rebel", "rebel", "loyalist", "loyalist" },
    }
  end

  function GameLogic:prepareForStart()
    local room = self.room
    local players = room.players
    self:addTriggerSkill(GameRule)
    for _, trig in ipairs(Fk.global_trigger) do
      if trig.name ~= "mobile_effect" then  --关闭手杀特效
        self:addTriggerSkill(trig)
      end
    end
    self.room:sendLog{ type = "$GameStart" }
  end

  function wjsl_logic:prepareDrawPile()
    local room = self.room
    --重新过滤卡组
    local filterCardIds = {}
    local allCardIds = Fk:getAllCardIds()
    local excepts = {"crossbow","indulgence","supply_shortage","lightning"} -- 删除一些卡组
    for i = 1, #allCardIds do
      local id = allCardIds[i]
      local card = Fk:getCardById(id)
      if card then
        if card.is_derived then
          table.insert(room.void, id)
          room:setCardArea(id, Card.Void, nil)
        else
          if table.contains(WHILEcards,card.package.name) then
            if not table.contains(excepts,card.trueName) then
              table.insert(filterCardIds,id)
            end
          end
        end
      end
    end
    table.shuffle(filterCardIds)
    room.draw_pile = filterCardIds
    for _, id in ipairs(room.draw_pile) do
      room:setCardArea(id, Card.DrawPile, nil)
    end
  end

  function wjsl_logic:assignRoles()
    local room = self.room
    local n = #room.players
    local roles = self.role_table[n]
    table.shuffle(roles)
    local bots_t = {}
    local players_t = {}
    for i = 1, n do
      local p = room.players[i]
      if p.id < 0 then
        table.insert(bots_t,{p.id,i})
      else
        table.insert(players_t,{p.id,i})
      end
    end
    local botsrand_t = table.random(bots_t)
    local bot_player = room.players[botsrand_t[2]]
    bot_player.role = "lord"
    bot_player.role_shown = true
    room:broadcastProperty(bot_player, "role")
    local loyalists = (n == 5 or n == 6) and 3 or 4
    local loyalistnum = 0
    for i = 1, n do
      local p = room.players[i]
      if p.role ~= "lord" then
        if p.id < 0 then
          if loyalistnum < loyalists then
            p.role = "loyalist"
            loyalistnum = loyalistnum + 1
          else
            p.role = "rebel"
          end 
        else
          p.role = "rebel"
        end
        p.role_shown = true
        room:broadcastProperty(p,"role")
      end
    end
  end

  function wjsl_logic:chooseGenerals()
    local room = self.room
    local lord = room:getLord()
    room.current = lord
    local nonlord = room.players

    self.endlPrac = nil
    self.endlPrac = EndLessPractice:new()
    self.endlPrac.all_generals = {}
    self.endlPrac.clone_generals = {}
    
    local io_obj
    if ISwrite then
      local io_obj = io.open("packages\\lang\\white_generals.txt","w")
    end
    local whitegens = GensLimts:getToTalGens()
    for _, gen in ipairs(whitegens) do
      local g = Fk.generals[gen]
      if g then
        table.insert(self.endlPrac.all_generals,g.name)
        table.insert(self.endlPrac.clone_generals,g.name)
        if ISwrite then
          local str = Fk:translate(g.name).."..来源于扩展包:".."【"..Fk:translate(g.package.name).."】".."\n"
          io_obj:write(str)
        end
      end
    end
    if ISwrite then io_obj:close() end

    local clohotgens = table.random(HOTgenerals,6)
    table.insertTable(clohotgens,table.random(self.endlPrac.all_generals,12))
    table.shuffle(clohotgens)
    table.shuffle(self.endlPrac.all_generals)
    local generalNum = 18
    local testgs = table.clone(TESTgens)
    -- local deadname,aliveone = "blank_shibing",true
    for _, p in ipairs(nonlord) do
      local arg = {}
      if p.id > 0 then
        for i = 1, generalNum do
          local g = clohotgens[i]
          if g then table.insert(arg, g) end
        end
        if IStest then table.insert(arg, TESTgen) end
      else
        if p.role == "loyalist" then
          table.insert(arg, "blank_shibing")
        else
          local autoselgen = (IStest and #testgs > 0) and table.remove(testgs,1) or table.remove(self.endlPrac.all_generals,1)
          table.insert(arg, autoselgen)
        end
      end
      p.request_data = json.encode({ arg, 1 })
      p.default_reply = arg[1]
    end

    room:doBroadcastRequest("AskForGeneral", nonlord)
    for _, p in ipairs(nonlord) do
      if p.general == "" and p.reply_ready then
        local general = json.decode(p.client_reply)[1]
        room:setPlayerGeneral(p, general, true, true)
      else
        room:setPlayerGeneral(p, p.default_reply, true, true)
      end
      p.default_reply = ""
    end

    room:askForChooseKingdom(nonlord)
    for _, p in ipairs(nonlord) do
      room:broadcastProperty(p, "general")
      if p.role == "lord" then
        room:broadcastProperty(p, "kingdom")
      end
    end
  end
  return wjsl_logic
end

--巅峰神塔模式
local wjsl_rule = fk.CreateTriggerSkill{
  name = "#wjsl_rule",
  priority = 0.001,
  refresh_events = {fk.GameStart,fk.BuryVictim,fk.GameOverJudge,fk.TurnStart,fk.DrawNCards},
  can_refresh = function(self, event, target, player, data)
    if event == fk.TurnStart then
      return player == target
    else
      return player.id < 0 and player.role == "lord"
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.BuryVictim then
      room:setTag("SkipGameRule", true)
      local body = room:getPlayerById(data.who)
      local logic = room.logic
      local endlPrac = logic.endlPrac
      local allgenerals = endlPrac.all_generals
      if not target.dying then return end
      if not allgenerals or #allgenerals == 0 then
        room:doBroadcastNotify("ShowToast", "将池耗尽")
        room:gameOver("rebel")
        return
      end
      --过了所有关卡胜利
      local curlayer = endlPrac:getLayer()
      --层主及队友都死亡
      --层主忠臣队友阵亡处理
      if body.role ~= "rebel" then
        endlPrac:bury(body)
        local lords = table.filter(room.alive_players,function(pr) return pr.id < 0 and GensLimts:isSameCamp(body,pr) end)
        if #lords > 0 then
          local draw = 2 + math.floor(curlayer / 10)
          endlPrac:drawCardsByCamp(draw,lords)
          if body.role ~= "lord" then return end
        end
      else
        --玩家阵亡处理
        if body.role == "rebel" then
          --守护天使效果
          if body:getMark("@@guardangle") > 0 then
            endlPrac:bury(body,SAVEmarks)
            room:revivePlayer(body, false)
            room:drawCards(body, 4 + (math.floor(curlayer/10) * 2),self.name)
            if room.current.role ~= body.role then
              endlPrac:endWhoPhase()
            end
            return
          end
          --全部阵亡结算
          local alivehumans = endlPrac:getAliveHumans()
          if #alivehumans <= 0 then
            room:doBroadcastNotify("ShowToast", "玩家全部阵亡，游戏结束。爬塔层数"..curlayer)
            room:gameOver("lord")
            return
          end
          --玩家阵亡处理
          endlPrac:bury(body,SAVEmarks)
          endlPrac:otherPlayersDraw(2+(math.floor(curlayer/10)*2))
          room:doBroadcastNotify("ShowToast", Fk:translate(body.general) .."阵亡，别放弃还有机会复活")
          return
        end
      end
      if curlayer >= endlPrac.totallayer then
        room:doBroadcastNotify("ShowToast", endlPrac.totallayer.."层！恭喜你爬到塔顶之巅。")
        room:gameOver("rebel")
        return
      end
      ----------------------------执行下一层逻辑--------------------------
      --boss死亡后获得其中一个技能
      local defeat
      if data.damage and data.damage.from and not data.damage.from.dead then
        defeat = data.damage.from
      end
      body = endlPrac:getLayerOwner()
      local otherplayers = endlPrac:getOPlayers(body)
      local lords = {}
      local rebels = -1
      for _,pr in ipairs(room.players) do
        if pr.id < 0 and GensLimts:isSameCamp(body,pr) and body.id ~= pr.id then table.insert(lords,pr) end
        if pr.id > 0 then rebels = rebels + 1 end
      end
      --复活层主队友或者其或者升级maxhp、技能数
      local extrafriend = endlPrac:getExtraFriendByLayers()
      local relifenum = math.floor((curlayer + 1) / extrafriend) + rebels 
      if #lords > 0 and relifenum > 0 then
        endlPrac:reLayerFriends(lords,math.min(relifenum,4))
      end
      --层主死亡层数+1并复活加强
      endlPrac:removeLayerBoss(defeat)
      endlPrac:changeLayer(1)
      --清除相关技能
      endlPrac:removeRelateSkills(body)
      --转变武将且复活
      local layer = endlPrac:getLayer()
      local haveboss = endlPrac:getLayerBoss()
      local newgeneral = endlPrac:changeGeneral(body,haveboss)
      if not newgeneral then
        room:doBroadcastNotify("ShowToast", "将池耗尽")
        room:gameOver("rebel")
        return
      end
      --删除复活前技能
      endlPrac:removeOldSkills(newgeneral,body)
      --刷新最大maxhp与hp
      local cal_add = math.floor(layer / endlPrac:getLayerSkillnum())
      if haveboss then
        cal_add = math.floor(cal_add * 2.5)
      end
      if cal_add > 0 then
        endlPrac:updateMax(body,cal_add)
      end
      --获得关卡技能
      endlPrac:getLaySkills(body)
      --层主或层队友每过n关获得随机技能
      local n = endlPrac:getRskiNum()
      if n > 0 then
        endlPrac:getRandSkills(n,body)
      end
      --刷新层数
      endlPrac:updateLayer(body,"@wj_layer")
      --通知其他角色层数
      endlPrac:notifyLayer("curlayerphase")
      --摸等量手牌
      endlPrac:drawByRelife(body)
      --------------------------------------------------------------------
      -----------------------玩家处理--------------------------------------
      --------------------------------------------------------------------
      if rebels > 0 and math.floor((curlayer + 1) / extrafriend) > math.floor(curlayer / extrafriend) and relifenum <= 4 and rebels + 1 ~= 3 then
        endlPrac:relifeAIRebels()
      end
      endlPrac:gainRandGold()
      endlPrac:meetPuYuan()
      endlPrac:addContiWin(1)
      --每3+（层数/10）关获得一次奖励
      local step = math.floor(layer / 10)
      local step_n = layer % 10
      local cal_step = step_n % (3 + step)
      if cal_step ~= 0 then
        --连胜超过一定回合结束当前阶段
        endlPrac:handleContiWin()
        return
      end
      --玩家潘多拉技能重置
      endlPrac:resetPdlSkills()
      --随机的奖励选项
      --开始选择
      endlPrac:layerRewards()
      --召唤潘多拉
      -- local call_n = 6 * #otherplayers
      -- endlPrac:callPanduola(body,call_n)
      --连胜超过一定回合结束当前阶段
      endlPrac:handleContiWin()
    elseif event == fk.GameStart then
      local room = player.room
      local logic = player.room.logic
      local endlPrac = logic.endlPrac
      local allgenerals = endlPrac.all_generals

      local otherplayers = endlPrac:getOPlayers(player)
      local humans,lordloyas = 0,0
      for _, pr in ipairs(room.players) do
        if pr.id > 0 then
          humans = humans + 1
        else
          if pr.role ~= "rebel" then
            lordloyas = lordloyas + 1
          end
        end
      end
      --规则限制
      if not endlPrac or #allgenerals == 0 then
        room:doBroadcastNotify("ShowToast", "模式或者人机无将池错误")
        room:gameOver(player.role)
        return
      end
      if #room.players ~=2 then
        if humans > 3 or lordloyas / humans <= 1 then
          room:doBroadcastNotify("ShowToast", "玩家数量过多不符合游戏规则")
          room:gameOver(player.role)
          return
        end
      else
        if humans ~= 1 then
          room:doBroadcastNotify("ShowToast", "玩家数量不符合游戏规则")
          room:gameOver(player.role)
          return
        end
      end
      
      local introduces = {"justsoso","justbored","justlike"}
      table.shuffle(introduces)
      for _, p in ipairs(room.players) do
        if p.id > 0 then
          if not IStest and not GensLimts:isGensPool(allgenerals,p.general) then
            room:doBroadcastNotify("ShowToast", Fk:translate(p.general).."不在白名单。游戏结束。具体白名单请看835104528群文件")
            room:gameOver(player.role)
            return
          end 
          local reply = room:askForCustomDialog(p,self.name,"packages/lang/qml/DialogChoiceBox.qml",{"author_says","dfst_introduce",introduces,"hxfc_author"})
          if reply == "justsoso" then 
            room:doBroadcastNotify("ShowToast", "幻想风车：看来我还需要考虑其他模式.....") 
            room:addPlayerMark(p,"@slash_num",1) 
          elseif reply == "justlike" then 
            room:doBroadcastNotify("ShowToast", Fk:translate(p.general).."承蒙喜欢❤") 
            room:addPlayerMark(p,"@slash_num",2)
          end
        else
          if p.role ~= "lord" then 
            if humans - 1 > 0 and p.role == "loyalist" then             
              humans = humans - 1
              endlPrac:changeGeneral(p)
            else
              if p.role == "rebel" then
                room:handleAddLoseSkills(p, "wjsl_zhenfen", nil, false)
              end
              room:killPlayer({ who = p.id }) 
            end
          end
        end
      end
      local gamedata = #room.players ~= 2 and table.clone(initGameData) or table.clone(initGameDataByLess)
      endlPrac:initData(player,gamedata)
      endlPrac:layerRewards()
    elseif event == fk.GameOverJudge then
      room:setTag("SkipGameRule", true)
    elseif event == fk.TurnStart then
      local room = player.room
      local lord = room:getLord()
      local endlPrac = lord.room.logic.endlPrac
      if endlPrac then endlPrac:setContiWin(0) end
    elseif event == fk.DrawNCards then
      -- local room = player.room
      local endlPrac = player.room.logic.endlPrac
      local haveboss = endlPrac:getLayerBoss()
      if haveboss then
        local layer = endlPrac:getLayer()
        local value = math.ceil(layer / 10) * 2
        data.n = data.n + value
      end
    end
  end,
}
Fk:addSkill(wjsl_rule)

local CurPhaseEnd = function (target,event)
  if target.phase == Player.NotActive then
      return
  end
  local room = target.room
  local mark = target:getMark("@wjsl_zhenta_num")
  mark = mark - 1
  room:setPlayerMark(target,"@wjsl_zhenta_num",mark)
  if mark < 1 then
    room:doBroadcastNotify("ShowToast", "结束当前阶段")
    local current = target.room.logic:getCurrentEvent()
    local usecard_event = current:findParent(event)
    if not usecard_event then return end
    local phase_event = usecard_event:findParent(GameEvent.Phase)
    if not phase_event then return end
    usecard_event:addExitFunc(function()
      phase_event:shutdown()
    end)
  end
end

--镇塔
local wjsl_zhenta = fk.CreateTriggerSkill{
  name = "wjsl_zhenta",
  frequency = Skill.Compulsory,
  events = {fk.TurnStart,fk.TurnEnd,fk.CardUseFinished,fk.AfterSkillEffect},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self.name) then
      return
    end
    if player == target then
      return
    end
    -- return player.room.current == target
    if event == fk.TurnStart or event == fk.TurnEnd then
      return player.room.current == target
    elseif event == fk.CardUseFinished then
      return true
    else
      return data.name == "wjsl_zhujia" and data.cost_data
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      local maxhp = target.maxHp
      if maxhp <= 5 then
        local value = 0
        if target.id > 0 and target.role == "rebel" then
          value = target.maxHp * 2
        end
        if target.id < 0 and target.role == "loyalist" then
          value = target.maxHp * 3
        end
        room:setPlayerMark(target,"@wjsl_zhenta_num",value)
      else
        local value = 0
        if target.id > 0 and target.role == "rebel" then
          value = math.min(10+(maxhp-5),15)
        end
        if target.id < 0 and target.role == "loyalist" then
          value = 15
        end
        room:setPlayerMark(target,"@wjsl_zhenta_num", value)
      end
      local shield_mark = target:getMark("wjsl_zhujia_shield") 
      if shield_mark > 0 then
        room:changeShield(target, -shield_mark)
        room:setPlayerMark(target,"wjsl_zhujia_shield",0)
      end
    elseif event == fk.CardUseFinished then
      CurPhaseEnd(target,GameEvent.UseCard)
    elseif event == fk.TurnEnd then
      -- body
      room:setPlayerMark(target,"@wjsl_zhenta_num",0)
    else
      CurPhaseEnd(target,GameEvent.SkillEffect)
    end
  end,
}
Fk:addSkill(wjsl_zhenta)

local df_fengkuang = fk.CreateTriggerSkill{
  name = "df_fengkuang",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.HpChanged,fk.DamageCaused},
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(self.name) then return end
    if event == fk.HpChanged then
      if player == target and player.id < 0 then
        if player:getMark("df_fengkuang") == 0 and player.hp <= player.maxHp / 2 then
          return true
        end
        if player:getMark("df_fengkuang") ~= 0 and player.hp > player.maxHp / 2 then
          return true
        end
      end
      return false 
    else
      return player == target and data.from == player and data.card and player.hp <= player.maxHp / 2
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.HpChanged then
      if player:getMark("df_fengkuang") ~= 0 and player.hp > player.maxHp / 2 then
        room:setPlayerMark(player,"df_fengkuang",0)
      end
      if player.hp <= player.maxHp / 2 then
        room:setPlayerMark(player,"df_fengkuang",1)
      end
    else
      data.damage = data.damage * 2
    end
  end,
}
Fk:addSkill(df_fengkuang)

--塔震
local wjsl_tazhen = fk.CreateTriggerSkill{
  name = "wjsl_tazhen",
  anim_type = "masochism",
  frequency = Skill.Compulsory,
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self.name) then
      return
    end
    return player == target and not player.dead and data.from and data.from~=player and data.damage > 1 and not data.from.dead
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local hands = data.from:getCardIds{Player.Hand}
    if #hands > data.damage then
      local randcards = table.random(hands,data.damage)
      room:throwCard(randcards,self.name,data.from,player)
    else
      data.from:throwAllCards("he")
    end
    room:damage{from = player,to = data.from,damage = data.damage,skillName = self.name}
  end,
}
Fk:addSkill(wjsl_tazhen)

local zhenfen_maxhands = fk.CreateMaxCardsSkill{
  name = "#zhenfen_maxhands",
  correct_func = function (self, player)
    if player:hasSkill("wjsl_zhenfen") and player:getMark("@df_lingxin") > 0 then
      return player:getMark("@df_lingxin")
    end
  end,
}
--振奋
local wjsl_zhenfen = fk.CreateTriggerSkill{
  name = "wjsl_zhenfen",
  frequency = Skill.Compulsory,
  anim_type = "offensive",
  events = {fk.TargetSpecifying,fk.DrawNCards,fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self.name) then
      return
    end
    if event == fk.TargetSpecifying then
      if player == target and data.card then
        if data.card.trueName == "slash" and player:getMark("@slash_dmg") > 0 then
          self.cost_data = "@slash_dmg"
          return true
        end
        if data.card.type == Card.TypeTrick and data.card.is_damage_card and player:getMark("@trick_dmg") > 0 then
          self.cost_data = "@trick_dmg"
          return true
        end
      end
    elseif event == fk.DrawNCards then
      return player:getMark("@df_lingxin") > 0 and player == target
    elseif event == fk.TurnStart then
      return player:getMark("@shieldnum") > 0 and player:getMark("@shieldnum") - player.shield > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecifying then
      data.additionalDamage = (data.additionalDamage or 0) + player:getMark(self.cost_data)
      self.cost_data = nil
    elseif event == fk.DrawNCards then
      data.n = data.n + player:getMark("@df_lingxin")
    elseif event == fk.TurnStart then
      player.shield = player:getMark("@shieldnum")
      room:broadcastProperty(player, "shield")
    end
  end,
}
local zhenfen_targetmod = fk.CreateTargetModSkill{
  name = "#zhenfen_targetmod",
  residue_func = function(self, player, skill, scope)
    if player:hasSkill(wjsl_zhenfen) and skill.trueName == "slash_skill" and scope == Player.HistoryPhase and player:getMark("@slash_num") > 0 then
      return player:getMark("@slash_num")
    end
  end,
}
wjsl_zhenfen:addRelatedSkill(zhenfen_maxhands)
wjsl_zhenfen:addRelatedSkill(zhenfen_targetmod)
Fk:addSkill(wjsl_zhenfen)

--铸甲
local wjsl_zhujia = fk.CreateActiveSkill{
    name = "wjsl_zhujia",
    -- anim_type = "support",
    min_card_num = 1,
    max_card_num = 2,
    can_use = function(self,player)
      return player:hasSkill(self.name) and player.phase == Player.Play and player:usedSkillTimes(self.name, Player.HistoryTurn) < math.ceil(player:getMark("curlayerphase") / 10) * 2 + 1
    end,
    card_filter = function(self, to_select, selected)
      local card = Fk:getCardById(to_select)
      if #selected == 0 then
        if card.type == Card.TypeEquip or card.name == "jink" then
          return true
        end
      elseif #selected == 1 then
        if Self.shield >= 5 then
          return
        end
        if Fk:getCardById(selected[1]).name == "jink" then
          return card.name == "jink"
        end
        if Fk:getCardById(selected[1]).type == Card.TypeEquip then
          return card.type == Card.TypeEquip
        end
      elseif #selected == 2 then
        return false
      end
    end,
    target_filter = function(self, to_select, selected)
        return false
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        self.cost_data = false
        if #effect.cards == 1 then
          room:recastCard(effect.cards, player, self.name)
        else
          self.cost_data = true
          room:throwCard(effect.cards,self.name,player,player)
          room:changeShield(player, 1)
          room:addPlayerMark(player,"wjsl_zhujia_shield",1)
        end
        
    end,
}
Fk:addSkill(wjsl_zhujia)

local wjsl_mode = fk.CreateGameMode{
  name = "wjsl_mode",
  minPlayer = 2,
  maxPlayer = 8,
  rule = wjsl_rule,
  logic = wjsl_getLogic,
  whitelist = table.clone(WHILEcards),
  winner_getter = function(self, victim)
    local room = victim.room
    local alive = table.filter(room.alive_players, function(p)
      return not p.surrendered
    end)
    if #alive ~= 1 then return "" end
    return alive[1].role
  end,
  surrender_func = function(self, playedTime)
    local surrenderJudge = { { text = "time limitation: 10s", passed = playedTime >= 10 } }
    if Self.role ~= "lord" then
      table.insert(surrenderJudge, { text = "1v1: left you alive", passed = true})
    end
    return surrenderJudge
  end,
}

Fk:loadTranslationTable{
  ["wjsl_mode"] = "巅峰神塔",
  ["#wjsl_rule"] = "巅峰神塔",
  ["@wj_layer"] = "层数:",

  ["wjsl_zhenta"] = "镇塔",
  [":wjsl_zhenta"] = "锁定技，每名其他角色回合开始时，使用牌会计入次数，计数为最大体力值的两倍（队友忠臣人机是3倍，最多15）（当玩家最大体力值超过5，计数只+1且最多为15），使用卡牌结算后或者因【铸甲】获得护甲，计数-1。当计数为0时结束当前阶段。",

  ["wjsl_zhujia"] = "铸甲",
  [":wjsl_zhujia"] = "出牌阶段限制（层数/10|向上取整）* 2次。你可以重铸1张【闪】或者【装备】牌，也可以丢弃两张【闪】或【装备】牌获得1枚护甲（最多为5护甲），该护甲在你下回合开始时如果还存在则失去先前获得数量",

  ["wjsl_tazhen"] = "塔震",
  [":wjsl_tazhen"] = "锁定技，当你受到其他角色大于1伤害后，你令伤害来源弃随机X张牌并受到X点伤害（X为受到伤害值）",

  ["df_fengkuang"] = "疯狂",
  [":df_fengkuang"] = "锁定技，当你体力为最大体力一半以及一半以下，你无视被禁用卡与使用对目标的卡被禁技能规则且你使用牌造成伤害翻倍（此技能只对人机有效）",

  ["@wjsl_zhenta_num"] = "计数",

  ["pdlboxreset"] = "魔盒：技能重置",

  ["author_says"] = "作者吟唱",
  ["dfst_introduce"] = "你觉得这个游戏模式玩起来怎么样？",
  ["justsoso"] = "感觉一般，凑合着玩",
  ["justlike"] = "卧槽！可以啊。点个赞！！！",
  ["justbored"] = "算了吧，下次不玩了~",

  ["#skills-choice"] = "随机选项选择",
  ["#relife-choice"] = "重生玩家请选择",
  ["#rstskills_1"] = "重置魔盒技能（需要5金币）",
  ["#rstskills_2"] = "重置魔盒技能（需要7金币）",
  ["#rstskills_3"] = "重置魔盒技能（需要10金币）",
  ["#rstskills_4"] = "重置魔盒技能（需要12金币）",
  ["#rstskills_5"] = "重置魔盒技能（需要15金币）",
  ["#getBossSkills-choice"] = "获取神将技能",
  ["#upAI-choice"] = "选择你要升级的AI队友",
  ["time limitation: 10s"] = "游戏长达10秒",
  ["1v1: left you alive"] = "任何时候，任何人数都可以投降",

  ["gaingold"] = "获得金币",
  [":gaingold"] = "获得金币随机40~70，层数越高随机金币下限有一定提升",
  ["maxhp"] = "成长",
  [":maxhp"] = "随机增加体力与最大体力值",
  ["extraslash_num"] = "连斩",
  [":extraslash_num"] = "你获得随机2-4随机【杀数+】标记，此标记能够在每个阶段使用杀次数额外增加对应标记值",
  ["angelbless"] = "天使祝福",
  [":angelbless"] = "天使祝福让你摸体力上限的手牌，回满体力，额外获得一层标记增益或者些许金币",
  ["magicbox"] = "魔盒的交易",
  [":magicbox"] = "你获得随机1-3【魔盒】标记（当获得该标记时，获得等量的随机技能。每到选项奖励可以用金币重置【魔盒】标记技能）",
  ["slash_dmg_sel"] = "【振奋】强化",
  [":slash_dmg_sel"] = "【振奋】强化【杀】，【杀】指向目标伤害+1",
  ["trick_dmg_sel"] = "【振奋】强化",
  [":trick_dmg_sel"] = "【振奋】强化【伤害锦囊】，【伤害锦囊】指向目标伤害+1",
  ["lingxin"] = "凌心",
  [":lingxin"] = "你获得随机1-3【凌心】标记，此标记能够使你的摸牌阶段摸牌数和手牌上限额外增加该标记值",
  ["shieldnum"] = "护盾",
  [":shieldnum"] = "你获得随机1-2随机【护甲+】标记，此标记能够在每回合开始把护甲叠到对应标记值",
  ["relife"] = "重生",
  [":relife"] = "你可以选择一名死亡玩家复活",
  ["guard_angel"] = "守护天使",
  [":guard_angel"] = "你活得“守护天使”标记，当你死亡时候可以满血复活并摸等量的牌，结束当前玩家回合阶段",
  ["rsetrwd_1"] = "重置奖励",
  [":rsetrwd_1"] = "可以花费20金币重置一次奖励",
  ["rsetrwd_2"] = "重置奖励",
  [":rsetrwd_2"] = "可以花费30金币重置一次奖励",
  ["rsetrwd_3"] = "重置奖励",
  [":rsetrwd_3"] = "可以花费40金币重置一次奖励",
  ["upAI"] = "升级人机",
  [":upAI"] = "升级你的人机队友，其最大体力与获得随机技能数+1，随机获得一些标记+1",

  ["@@guardangle"] = "守护天使",
  ["@slash_dmg"] = "杀伤+",
  ["@trick_dmg"] = "锦伤+",
  ["@slash_num"] = "杀数+",
  ["@pdlbox"] = "魔盒+",
  ["@df_lingxin"] = "凌心+",
  ["@shieldnum"] = "护甲+",
  ["@gold_num"] = "金币:",

  ["pyshop_buyitems"] = "购买装备",
  ["pyshop_cellskills"] = "出售技能",
  ["#puyuanShop-choice"] = "浦元铁匠铺",
  ["#puyuanShop-buyeuips"] = "购买装备药水",
  ["#puyuanShop-cellskills"] = "出售技能",
  ["Exist"] = "离开",

  ["wjsl_zhenfen"] = "振奋",
  [":wjsl_zhenfen"] = "锁定技，【杀】、【伤害锦囊】指定目标的伤害值+获得强化的标记值，【护甲】、【凌心】每回合获得护甲和摸牌数也依此类推",

  ["wjsl_tips"] = "新手提示",
  ["wjsl_title"] = "新手提示",
  [":wjsl_title"] = "1.塔层共60层，难度逐层递增。下一层复活的层主摸牌数是根据玩家手牌、连胜次数来计算。<br/>2.玩家连胜5次将终结其阶段(超过40层改为4)，如果是多人玩家层主还会获得一个额外的回合。<br/>3.请不要摸牌过多以至于牌堆为0平局。",
  ["wjsl_title1"] = "浦沅商店",
  [":wjsl_title1"] = "层数大于10有概率遇到，可以买药水、稀有装备、技能。也可以卖技能（潘多拉技能除外）",
  [":wjsl_mode"] = desc_wjsl_mode,
}

return wjsl_mode
